<?php

Class OwnerEvaluationsController extends AppController {

    public $name = 'OwnerEvaluations';

    function edit($evaluation_id) {
        $this->layout = "ajax";
        $this->OwnerEvaluation->recursive = -1;
        if (empty($this->data)) {

            $this->data = $this->OwnerEvaluation->find('first', array('conditions' => array('OwnerEvaluation.id' => $evaluation_id), 'fields' => array('OwnerEvaluation.concepto', 'OwnerEvaluation.calificacion', 'OwnerEvaluation.owner_id', 'OwnerEvaluation.id')));
        } else {

            if ($this->OwnerEvaluation->save($this->data)) {
                $this->Session->setFlash('Registro editado correctamente', 'flash_custom');
                $this->redirect(array('controller' => 'ownerEvaluations', 'action' => 'index', $this->data['OwnerEvaluation']['owner_id']));
            } else {
                $this->Session->setFlash('Error editando datos');
            }
        }
    }

    function add($owner_id) {
        $this->layout = "ajax";
        $datos = array('OwnerEvaluation' => array(
                'owner_id' => $owner_id
                ));
         $this->OwnerEvaluation->create();
        if ($this->OwnerEvaluation->saveAll($datos)) {
            $this->Session->setFlash('Registro Adicionado correctamente', 'flash_custom');
            $this->redirect(array('controller' => 'OwnerEvaluations', 'action' => 'index', $owner_id));
        }
    }

    function index($owner_id,$property_id) {
        $this->layout = "ajax";
        $this->set('owner_id', $owner_id);
        $this->set('property_id', $property_id);
        $this->OwnerEvaluation->recursive = -0;
        $this->paginate = array('OwnerEvaluation' => array('maxLimit' => 500, 'limit' => 50, 'fields' => array('OwnerEvaluation.id', 'OwnerEvaluation.concepto', 'OwnerEvaluation.calificacion', 'OwnerEvaluation.id','Owner.nombres','Owner.primer_apellido')));
        $this->set('OwnerEvaluations', $this->paginate(array('OwnerEvaluation.owner_id' => $owner_id)));
    }
    
    
    function delete($evaluation_id,$owner_id) {
        if($this->OwnerEvaluation->delete($evaluation_id)){
            $this->OwnerEvaluation->OwnerRequirement->deleteAll(array('OwnerRequirement.owner_evaluation_id'=>$evaluation_id) );
            $this->Session->setFlash('Registro borrado correctamente', 'flash_custom');
            $this->redirect(array('controller' => 'OwnerEvaluations', 'action' => 'index', $owner_id));
        }
        
    }

}

?>